﻿@using GameSchool.HtmlHelpers
@model GameSchool.ViewModels.Exam.CreateViewModel
@{
    ViewBag.Title = "Skrá nýtt próf fyrir " + +Model.currentCourse.Code + Model.currentCourse.Name + Model.currentCourse.Semester.Year + "-" + Model.currentCourse.Semester.SemesterOfYear;
}
<h2>
    Skrá nýtt próf fyrir @Model.currentCourse.Code, @Model.currentCourse.Name</h2>
<p>
    Notaðu formið hér að neðan til þess að skrá nýtt próf fyrir @Model.currentCourse.Code,
    @Model.currentCourse.Name á önninni @Model.currentCourse.Semester.Year-@Model.currentCourse.Semester.SemesterOfYear.
</p>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm(htmlAttributes: new { @class = "form-horizontal" }))
{
    @Html.ValidationSummary(true, "Ekki tókst að skrá nýtt próf. Vinsamlegast leiðréttu villurnar og reyndu aftur.")
    <div>
        <fieldset>
            <legend>Prófaupplýsingar</legend>
            <div class="control-group">
                @Html.LabelFor(m => m.exam.Name, new { @class = "control-label" }, "Heiti")
                <div class="controls">
                    @Html.TextBoxFor(m => m.exam.Name, new { @class = "input-xxlarge", placeholder = "Heiti prófs" })
                    @Html.ValidationMessageFor(m => m.exam.Name)
                </div>
            </div>
            <div class="control-group">
                @Html.LabelFor(m => m.exam.Description, new { @class = "control-label" }, "Lýsing")
                <div class="controls">
                    @Html.TextAreaFor(m => m.exam.Description, new { @class = "input-xxlarge", rows = "8", placeholder = "Lýsing á prófi" })
                    @Html.ValidationMessageFor(m => m.exam.Description)
                </div>
            </div>
            <div class="control-group">
                @Html.LabelFor(m => m.exam.HoursToFinish, new { @class = "control-label" }, "Tími til að ljúka prófi")
                <div class="controls">
                    @Html.TextBoxFor(m => m.exam.HoursToFinish, new { @class = "input-small", placeholder = "(klst)", type = "number" })
                    @Html.ValidationMessageFor(m => m.exam.HoursToFinish)
                </div>
            </div>
            <div class="control-group">
                @Html.LabelFor(m => m.exam.GradePercentage, new { @class = "control-label" }, "Vægi í lokaeinkunn")
                <div class="controls">
                    @Html.TextBoxFor(m => m.exam.GradePercentage, new { @class = "input-small", placeholder = "(%)", type = "number" })
                    @Html.ValidationMessageFor(m => m.exam.GradePercentage)
                </div>
            </div>
            @Html.Hidden("ExamQuestionCounter", 1)
            @{
                Html.RenderAction("AddQuestion", new { id = 1 });
            }
            <div class="form-actions">
                <input type="submit" class="btn btn-primary" value="Skrá próf" />
                <a href="@Url.Action("List", new { id = Model.currentCourse.CourseID })" class="btn">Til baka í prófalista</a> <a id="add-question"
                    href="#" class="btn btn-success">Bæta við spurningu</a>
            </div>
        </fieldset>
    </div>
}
<script type="text/javascript">
    $('#add-question').on('click', function (event) {
        event.preventDefault();
        // Incrementa counternum
        $('#ExamQuestionCounter').val(parseInt($('#ExamQuestionCounter').val()) + 1);
        // Ná í incrementað value
        var examQuestionCounter = $('#ExamQuestionCounter').val();

        $.get('/Exam/AddQuestion/' + examQuestionCounter, function (html) {
            $(html).insertBefore('.form-actions');

        });
    });

    $('.remove-question').live('click', function (event) {
        event.preventDefault();

        $(this).parents('div.question:first').remove();
    });

        
</script>
